import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, SetMetadata, Req, Query, HttpStatus } from '@nestjs/common';
import { EnterpriseService } from './enterprise.service';
import { CreateEnterpriseDto, ListEnterpriseDto, UpdateEnterpriseDto } from './dto/index';
import { ApiTags } from '@nestjs/swagger';
import { RequireRole } from 'src/common/decorator/require-role.decorator';
import { RoleEnum } from 'src/common/enum/index';
import { ResultData } from 'src/common/utils/result';
import { Request } from 'express';

@Controller('enterprise')
@ApiTags('企业管理端')
export class EnterpriseController {
  constructor(private readonly enterpriseService: EnterpriseService) {}

  @Get('list')
  async findAll(@Query() query: ListEnterpriseDto) {
    const result = await this.enterpriseService.findAll(query);
    return ResultData.ok(result);
  }

  @Get(':enterpriseId')
  async getEnterpriseInfo(@Param('enterpriseId') id: string) {
    const result = await this.enterpriseService.findOne(id);
    if (!result) return ResultData.fail(HttpStatus.NOT_FOUND, '企业不存在');
    return ResultData.ok(result);
  }

  @Post()
  @RequireRole([RoleEnum.enterprise_boss])
  async create(@Body() createEnterpriseDto: CreateEnterpriseDto) {
    const result = await this.enterpriseService.create(createEnterpriseDto);
    return ResultData.ok(result);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateEnterpriseDto: UpdateEnterpriseDto) {
    return this.enterpriseService.update(+id, updateEnterpriseDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.enterpriseService.remove(+id);
  }
}
